package heiing.collection.diff;

import java.util.List;
import java.util.stream.Collectors;

/**
 *
 * @author heiing
 * @param <T>
 */
public interface ListDiff<T> {

    default CollectionDiffResult<T> diff(List<T> a, List<T> b) {
        if (null == b || b.isEmpty()) {
            return new CollectionDiffResult<>(null, a);
        }
        if (null == a || a.isEmpty()) {
            return new CollectionDiffResult<>(b, null);
        }
        return new CollectionDiffResult<>(
            b.stream().filter(x -> !a.contains(x)).collect(Collectors.toList()),
            a.stream().filter(x -> !b.contains(x)).collect(Collectors.toList())
        );
    }

}
